package testing;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import logic.English;
import logic.PlayfairCipher;
import logic.PlayfairKey;
import cruncher.TetragraphMap;
import cruncher.WordMap;

public class Test7 {

	public static void main(String[] args) {
		PlayfairCipher cipher = new PlayfairCipher(new English(), "playfairexample");
		TetragraphMap tetra = new TetragraphMap(cipher);
		WordMap wmap = new WordMap("english-dict.txt");
		wmap.prepList(new String[] { "probably", "language", "journal"});
		
		tetra.loadBinary("tetragraphs.bin");
		
		try {
			Scanner s = new Scanner(new File("cipher.txt"));
			
			String line = s.nextLine().toLowerCase();
			
			PlayfairKey.cipher = cipher;
			PlayfairKey.cipherText = line;
			PlayfairKey.tetraMap = tetra;
			PlayfairKey.wordMap = wmap;
			
			PlayfairKey key = PlayfairKey.generateRandomKey(cipher.getLanguage());
			key.findSolution(line, 100);
			
			System.out.println("Done!");
			
			cipher.setKey(key);
			System.out.println("Decipher : " + cipher.decipherString(line));
			System.out.println(key);
			
		}
		catch (FileNotFoundException e) {}
	}

}
